import { Column, Entity, Index, JoinColumn, ManyToOne } from 'typeorm';
import { CommonEntity, CommonStatus } from '~/common/entity/common.entity';
import { UserEntity } from '~/modules/user/user.entity';
import { MissionEntity } from './mission.entity';

@Entity({ name: 'ah_mission_user' })
@Index(['id'])
export class MissionUserEntity extends CommonEntity {
  @ManyToOne(() => MissionEntity, (mission) => mission.missionUsers)
  @JoinColumn({ name: 'mission_id' })
  mission: MissionEntity;

  @ManyToOne(() => UserEntity, (user) => user.missionUsers)
  @JoinColumn({ name: 'user_id' })
  user: UserEntity;

  // 完成次数
  @Column({ type: 'int', comment: '完成次数', default: 0 })
  completedCount: number;

  @Column({ type: 'tinyint', width: 1, comment: '是否完成', default: CommonStatus.NO })
  isCompleted: CommonStatus;

  @Column({ type: 'datetime', nullable: true, comment: '完成时间' })
  completedAt: Date;
}
